<template>
  <div class="wrap">
    <h3 class="product-name">{{ product.name }}</h3>
    <ul class="tags" v-if="product.tag">
      <li v-for="(item, index) in product.tag.split(',')" :key="index">{{ item }}</li>
    </ul>
    <div class="desc" v-if="product.customerDesc">
        <div class="editor" v-html="product.customerDesc.replace(/[\n\r]/g, '<br/>')"></div>
    </div>
    <van-tabs v-model="active" border color="#FE9100" title-active-color="#121C32" title-inactive-color="#9DA1AC" line-width="34" line-height="4" swipeable animated>
      <van-tab title="产品大纲">
        <div class="editor" v-html="product.outline"></div>
      </van-tab>
      <van-tab title="进件流程">
        <div class="editor" v-html="product.applyProcess"></div>
      </van-tab>
      <van-tab title="常见问题">
        <ul class="question-list">
          <li class="van-hairline--bottom van-ellipsis" v-for="(item, index) in questionList" :key="index" @click="handleQuestion(item)">{{ item.title }}</li>
        </ul>
      </van-tab>
      <van-tab title="客户案例">
        <div class="editor" v-html="product.customerCase"></div>
      </van-tab>
    </van-tabs>
    <div class="btn-container">
      <div class="left">
        <img :src="product.managerHeadImg" alt="" />
        <p class="van-ellipsis">{{ product.managerName }}</p>
      </div>
      <div class="right">
        <van-button color="#289EF2" :url="`tel:${product.managerPhone}`" icon="https://tyqf-bucket.oss-cn-beijing.aliyuncs.com/other/phone.png" class="call">咨询上级</van-button>
        <van-button color="#FE9200" class="apply" @click="apply">立即申请</van-button>
      </div>
    </div>
    <van-popup v-model="question.show" closeable position="bottom" :style="{ height: '60%' }">
      <div class="question-title van-hairline--bottom">{{ question.title }}</div>
      <div class="question-content">{{ question.content }}</div>
    </van-popup>
  </div>
</template>

<script>
import { product_getProductDetailNew, product_getCommonQuestion } from '@api/service';
import { Toast, Tabs, Tab, Popup, Button } from 'vant';
export default {
  components: {
    [Popup.name]: Popup,
    [Button.name]: Button,
    [Tabs.name]: Tabs,
    [Tab.name]: Tab
  },
  data() {
    return {
      active: 0,
      product: {},
      questionList: [],
      question: { show: false }
    };
  },
  mounted() {
    this.getProductDetail();
    this.getQuestionList();
  },
  methods: {
    handleQuestion(item) {
      this.question = {
        show: true,
        ...item
      };
    },
    async getQuestionList() {
      let res = await product_getCommonQuestion({ productId: this.$route.query.id });
      if (res.code === 200) {
        this.questionList = res.data;
      } else {
        Toast(res.msg);
      }
    },
    async getProductDetail() {
      let res = await product_getProductDetailNew({ id: this.$route.query.id });
      if (res.code === 200) {
        let obj = {};
        res.data.attrList.forEach(todo => {
          obj[todo.key] = todo.value;
        });
        this.product = {
          ...res.data,
          ...obj
        };
      } else {
        Toast(res.message);
      }
    },
    apply() {
      this.$emit('submit');
    }
  }
};
</script>

<style lang="scss" scoped>
.wrap {
  background: #fff;
  padding: 30px 30px 140px;
}
.van-tabs {
  position: relative;
  left: -30px;
  width: 100vw;
}
.product-name {
  font-size: 40px;
  color: #292f3d;
  margin-bottom: 30px;
}
.tags {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  li {
    display: inline-block;
    padding: 5px 10px;
    background: #fdf4e7;
    color: #fe9100;
    font-size: 24px;
    font-weight: bold;
    border-radius: 4px;
    margin-right: 10px;
  }
}
.desc {
  background: #edebe7;
  font-size: 26px;
  line-height: 40px;
  color: #53360e;
  border-radius: 10px;
  margin-bottom: 80px;
}
/deep/ .van-tabs__wrap:after {
  border-top: none;
}
.van-tab__pane-wrapper {
  min-height: 60vh;
}
.question-title {
  display: flex;
  align-items: center;
  font-weight: bold;
  min-height: 75px;
  line-height: 40px;
  padding-left: 24px;
  padding: 15px 70px 15px 24px;
  font-size: 30px;
  margin-bottom: 15px;
}
.question-content {
  font-size: 28px;
  padding: 0 24px;
  line-height: 36px;
}
.question-list {
  li {
    line-height: 100px;
    padding: 0 30px;
    font-size: 28px;
    &:before {
      content: '';
      position: absolute;
      right: 24px;
      width: 12px;
      height: 24px;
      top: 50%;
      margin-top: -12px;
      background: url('../../assets/images/arrow_right.png') no-repeat top;
      background-size: 100% 100%;
    }
  }
}
.btn-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 134px;
  background: #fff;
  box-shadow: 1px 5px 50px 0px rgba(42, 48, 62, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30px;
  box-sizing: border-box;
  .left {
    text-align: center;
    font-size: 24px;
    color: #2a303e;
    max-width: 130px;
    img {
      width: 68px;
      height: 68px;
      border-radius: 50%;
    }
  }
  .right {
    display: flex;
    align-items: center;
    button {
      width: 230px;
      height: 90px;
      line-height: 90px;
      padding: 0;
      text-align: center;
      color: #fff;
      font-size: 30px;
      font-weight: bold;
      margin-left: 18px;
    }
  }
}
</style>
